Skip to content

fix: print "Listening on" only after the socket is bound (#4400)#4413

Merged
schloerke merged 2 commits into
mainfrom
schloerke/fix-4400-listening-order
Jul 15, 2026
Merged

fix: print "Listening on" only after the socket is bound (#4400)#4413
schloerke merged 2 commits into
mainfrom
schloerke/fix-4400-listening-order

Conversation

@schloerke

Copy link
Copy Markdown
Collaborator

Fixes #4400

Summary

The Listening on http://… startup message was emitted one statement before the startServer() call that binds the listening socket. Because httpuv binds synchronously, moving the message to after startServer()/startPipeServer() returns guarantees the announced URL is already accepting connections. The domain-socket branch also validates the mask attribute before binding so an invalid socket errors without printing a misleading line. This matters because the Listening on line is used as a readiness signal (shinytest2, process supervisors, log watchers); under load the freshly-forked process could be descheduled between the two statements, leaving a window where the advertised port refused connections.

Verification

Unit tests in tests/testthat/test-server.R mock the synchronous bind and assert the message is emitted only after it returns (and not at all under quiet = TRUE). Reverting the reorder makes the ordering test fail; restoring it passes. Manual reproduction using the issue reporter's tracer now shows the port accepting connections by the time the line prints.

Emit the "Listening on ..." startup message after startServer()/
startPipeServer() returns rather than before, so the announced URL is
guaranteed to be accepting connections. httpuv binds synchronously, so
by the time the handle is returned the port is live. Previously the
message could be printed one statement before the bind, leaving a window
(widened under load) where anything scraping the line as a readiness
signal (shinytest2, log watchers) could reach a not-yet-bound port.
@schloerke
schloerke marked this pull request as ready for review July 15, 2026 18:26
@schloerke
schloerke merged commit 694a75f into main Jul 15, 2026
12 checks passed
@schloerke
schloerke deleted the schloerke/fix-4400-listening-order branch July 15, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shiny's startApp() prints "Listening on …" before binding the listening socket

1 participant